package com.firstgroup.service.Impl;

import com.firstgroup.domain.Evaluate;
import com.firstgroup.domain.Interviewers;
import com.firstgroup.domain.User;
import com.firstgroup.repository.EvaluateRepository;
import com.firstgroup.repository.InterviewersRepository;
import com.firstgroup.repository.UserRepository;
import com.firstgroup.service.EvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EvaluateServiceImpl implements EvaluateService {
    @Autowired
    EvaluateRepository evaluateRepository;
    @Autowired
    InterviewersRepository interviewersRepository;
    @Autowired
    UserRepository userRepository;

    @Override
    public Evaluate addCounts(Evaluate evaluate) {
     Evaluate evaluate1=   evaluateRepository.save(evaluate);
        return evaluate1;
    }

    @Override
    public List<Evaluate> findByInterviewerId(int InterviewerId) {
        return null;
    }


    @Override
    public List<Object[]> find(int interviewerId, String value) {
        return evaluateRepository.find(interviewerId,value);
    }


    public Evaluate addCountOne(int userid,int interviewerId,int heart,int communicate,
                                      int study,int strain,int compression,int attitude,int understand){

        Interviewers interviewers=interviewersRepository.findByInterviewersId(interviewerId);

        User user=userRepository.findById(userid);
        Evaluate evaluate=new Evaluate();
        evaluate.setUserid(userid);
        evaluate.setInterviewerId(interviewerId);
        evaluate.setCommunicate(communicate);
        evaluate.setCompression(compression);
        evaluate.setStrain(strain);
        evaluate.setStudy(study);
        evaluate.setAttitude(attitude);
        evaluate.setUnderstand(understand);
        evaluate.setValue("一面");
        evaluate.setHeart(heart);
        evaluate.setInterviewerName(interviewers.getName());
        evaluate.setUsername(user.getName());
        evaluate.setSum(heart+communicate+study+strain+compression+attitude+understand);
        Evaluate evaluate2= evaluateRepository.save(evaluate);
        return evaluate2;

    }

    public Evaluate addCountTwo(int userid,int interviewerId,int heart,int communicate,
                                int study,int strain,int compression,int attitude,int understand){
        Interviewers interviewers=interviewersRepository.findByInterviewersId(interviewerId);
        User user=userRepository.findById(userid);
        Evaluate evaluate=new Evaluate();
        evaluate.setUserid(userid);
        evaluate.setInterviewerId(interviewerId);
        evaluate.setCommunicate(communicate);
        evaluate.setCompression(compression);
        evaluate.setStrain(strain);
        evaluate.setStudy(study);
        evaluate.setAttitude(attitude);
        evaluate.setUnderstand(understand);
        evaluate.setValue("二面");
        evaluate.setHeart(heart);
        evaluate.setInterviewerName(interviewers.getName());
        evaluate.setUsername(user.getName());
        evaluate.setSum(heart+communicate+study+strain+compression+attitude+understand);
       Evaluate evaluate2= evaluateRepository.save(evaluate);
        return evaluate2;

    }


    public List<Evaluate> findAccount(int interviewersId, String value) {
        List<Evaluate>  list=  evaluateRepository.findByInterviewerIdAndValue(interviewersId, value);
        return list;
    }


}
